package com.itheima.spring;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.HandshakeInterceptor;

@Configuration
@EnableWebSocket    //启用 WebSocket
public class MyWsConfig implements WebSocketConfigurer {

    @Autowired
    private MyWsHandler myWsHandler ;

    @Autowired
    private  MyWsInterceptor myWsInterceptor ;

    /**
     * 注册拦截器
     */
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(new MyWsHandler(), "/myWs1").addInterceptors((HandshakeInterceptor) new MyWsInterceptor()) ;
    }
}
